package com.itlong.cloud.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.POJO.PO.DeviceBusinessElevatorChangeLogPO;
import com.itlong.cloud.dao.ICloudElevatorChangeBusinessDao;
import com.itlong.cloud.service.ICloudElevatorChangeBusinessService;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <desc>
 *      云电梯设备管理服务接口实现
 * </desc>
 *
 * @createDate 2017-11-15.
 */
@Service
public class CloudElevatorChangeBusinessServiceImpl implements ICloudElevatorChangeBusinessService {
    private static final Logger LOG = LoggerFactory.getLogger(CloudElevatorChangeBusinessServiceImpl.class);
    //云电梯持久层接口
    @Autowired
    ICloudElevatorChangeBusinessDao iCloudElevatorChangeBusinessDao;





    /**
     * <desc>
     *     云电梯_批量保存设备端推送指令
     * </desc>
     * @param deviceBusinessElevatorChangeLogPOs
     * @return
     * @throws Exception
     *
     * @author Jiaqi.X
     * @createDate 2018/04/03
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer saveDeviceBusinessChangeLogBatch(List<DeviceBusinessElevatorChangeLogPO> deviceBusinessElevatorChangeLogPOs) throws Exception{
        try {
            if (deviceBusinessElevatorChangeLogPOs != null&&deviceBusinessElevatorChangeLogPOs.size()>0){
                int result = iCloudElevatorChangeBusinessDao.saveDeviceBusinessChangeLogBatch(deviceBusinessElevatorChangeLogPOs);
            }
            return  1;
        }catch (Exception e){
            LOG.error("【云对讲_接收设备推送指令_保存异常】"+"\n"+ "异常数据:" + JSONObject.toJSONString(deviceBusinessElevatorChangeLogPOs));
            return 0;
        }
    }
    /**
     * <desc>
     *     根据房间ID查询对应的楼栋与单元ID
     * </desc>
     *
     * @param roomId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/04/03
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public String deviceChangeLogGetBuildAndUnitIdByRoomId(String roomId){
        return iCloudElevatorChangeBusinessDao.deviceChangeLogGetBuildAndUnitIdByRoomId(roomId);
    }

    /**
     * <desc>
     *     根据设备唯一码查询设备电梯类型
     * </desc>
     *
     * @param deviceUnique 设备唯一码
     * @return
     * @author JuGuang.S
     * @createDate 2018/06/13
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer findElevatorTypeByDeviceUnique(String deviceUnique){
        return iCloudElevatorChangeBusinessDao.findElevatorTypeByDeviceUnique(deviceUnique);
    }



}
